package com.lineage.data.item_etcitem;

import com.add.system.ACard;
import com.add.system.ACardTable;
import com.add.system.CardPolySet;
import com.add.system.CardSetTable;
import com.lineage.data.executor.ItemExecutor;
import com.lineage.server.model.Instance.L1ItemInstance;
import com.lineage.server.model.Instance.L1PcInstance;
import com.lineage.server.serverpackets.S_SkillSound;
import com.lineage.server.serverpackets.S_SystemMessage;
import com.lineage.server.serverpackets.ServerBasePacket;

public class Cards extends ItemExecutor {
  private int _quest;
  
  private int _gfx;
  
  private static Cards _instance;
  
  public static ItemExecutor get() {
    return new Cards();
  }
  
  public static Cards getInstance() {
    if (_instance == null)
      _instance = new Cards(); 
    return _instance;
  }
  
  public void execute(int[] data, L1PcInstance pc, L1ItemInstance item) {
    if (item == null)
      return; 
    if (pc == null)
      return; 
    if (pc.isPrivateShop()) {
      pc.sendPackets((ServerBasePacket)new S_SystemMessage("摆摊状态下 无法使用"));
      return;
    } 
    if (pc.isFishing()) {
      pc.sendPackets((ServerBasePacket)new S_SystemMessage("钓鱼状态下 无法使用"));
      return;
    } 
    boolean ok = false;
    int i = 0;
    while (i <= ACardTable.get().ACardSize()) {
      ACard card = ACardTable.get().getCard(i);
      if (card != null && card.getQuestId() == this._quest) {
        if (pc.getQuest().get_step(card.getQuestId()) == 0) {
          pc.getQuest().set_step(card.getQuestId(), 1);
          pc.getInventory().removeItem(item, 1L);
          pc.sendPackets((ServerBasePacket)new S_SystemMessage("你已成功登录此卡片 请重新登入获得能力加成 并享有此变身能力"));
          pc.sendPacketsAll((ServerBasePacket)new S_SkillSound(pc.getId(), this._gfx));
          ok = true;
          break;
        } 
        pc.sendPackets((ServerBasePacket)new S_SystemMessage("无法重复登录卡片"));
        break;
      } 
      i++;
    } 
    if (ok) {
      i = 0;
      while (i <= CardSetTable.get().CardCardSize()) {
        CardPolySet cards = CardSetTable.get().getCard(i);
        if (cards != null) {
          int k = 0;
          int j = 0;
          while (j < (cards.getNeedQuest()).length) {
            if (pc.getQuest().get_step(cards.getNeedQuest()[j]) != 0)
              k++; 
            j++;
          } 
          if (k == (cards.getNeedQuest()).length) {
            pc.getQuest().set_step(cards.getQuestId(), 1);
            pc.sendPackets((ServerBasePacket)new S_SystemMessage("恭喜你启动此变身卡套装卡能力"));
          } 
        } 
        i++;
      } 
    } 
  }
  
  public void set_set(String[] set) {
    try {
      this._quest = Integer.parseInt(set[1]);
    } catch (Exception exception) {}
    try {
      this._gfx = Integer.parseInt(set[2]);
    } catch (Exception exception) {}
  }
}
